using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

using SharpCore.Data;

namespace TF.Access {
	public partial class TF_EventView {
		#region Fields
		private int id;
		private int cityID;
		private int viewId;
		private double viewPrice;
		private DateTime startDate = System.Data.SqlTypes.SqlDateTime.MinValue.Value;
		private DateTime endDate = System.Data.SqlTypes.SqlDateTime.MinValue.Value;
		private string memo;
		#endregion
		
		#region Constructors
		/// <summary>
		/// Initializes a new instance of the TF_EventView class.
		/// </summary>
		public TF_EventView() {
		}
		
		/// <summary>
		/// Initializes a new instance of the TF_EventView class.
		/// </summary>
		public TF_EventView(int cityID, int viewId, double viewPrice, DateTime startDate, DateTime endDate, string memo) {
			this.cityID = cityID;
			this.viewId = viewId;
			this.viewPrice = viewPrice;
			this.startDate = startDate;
			this.endDate = endDate;
			this.memo = memo;
		}
		
		/// <summary>
		/// Initializes a new instance of the TF_EventView class.
		/// </summary>
		public TF_EventView(int id, int cityID, int viewId, double viewPrice, DateTime startDate, DateTime endDate, string memo) {
			this.id = id;
			this.cityID = cityID;
			this.viewId = viewId;
			this.viewPrice = viewPrice;
			this.startDate = startDate;
			this.endDate = endDate;
			this.memo = memo;
		}
		#endregion
		
		#region Properties
		/// <summary>
		/// Gets or sets the Id value.
		/// </summary>
		public int Id {
			get { return id; }
			set { id = value; }
		}
		
		/// <summary>
		/// Gets or sets the CityID value.
		/// </summary>
		public int CityID {
			get { return cityID; }
			set { cityID = value; }
		}
		
		/// <summary>
		/// Gets or sets the ViewId value.
		/// </summary>
		public int ViewId {
			get { return viewId; }
			set { viewId = value; }
		}
		
		/// <summary>
		/// Gets or sets the ViewPrice value.
		/// </summary>
		public double ViewPrice {
			get { return viewPrice; }
			set { viewPrice = value; }
		}
		
		/// <summary>
		/// Gets or sets the StartDate value.
		/// </summary>
		public DateTime StartDate {
			get { return startDate; }
			set { startDate = value; }
		}
		
		/// <summary>
		/// Gets or sets the EndDate value.
		/// </summary>
		public DateTime EndDate {
			get { return endDate; }
			set { endDate = value; }
		}
		
		/// <summary>
		/// Gets or sets the Memo value.
		/// </summary>
		public string Memo {
			get { return memo; }
			set { memo = value; }
		}
		#endregion
		
		#region Methods
		/// <summary>
		/// Saves a record to the TF_EventView table.
		/// </summary>
		public void Insert() {
			id = Convert.ToInt32(SqlClientUtility.ExecuteScalar("TF_EventViewInsert", cityID, viewId, viewPrice, startDate, endDate, memo));
		}
		
		/// <summary>
		/// Updates a record in the TF_EventView table.
		/// </summary>
		public void Update() {
			SqlClientUtility.ExecuteNonQuery("TF_EventViewUpdate", id, cityID, viewId, viewPrice, startDate, endDate, memo);
		}
		
		/// <summary>
		/// Deletes a record from the TF_EventView table by its primary key.
		/// </summary>
		public void Delete() {
			SqlClientUtility.ExecuteNonQuery("TF_EventViewDelete", id);
		}
		
		/// <summary>
		/// Selects a single record from the TF_EventView table.
		/// </summary>
		public static TF_EventView Select(int id) {
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader("TF_EventViewSelect", id)) {
				if (dataReader.Read()) {
					return MakeTF_EventView(dataReader);
				} else {
					return null;
				}
			}
		}
		
		/// <summary>
		/// Selects all records from the TF_EventView table.
		/// </summary>
		public static List<TF_EventView> SelectAll() {
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader("TF_EventViewSelectAll")) {
				List<TF_EventView> tF_EventViewList = new List<TF_EventView>();
				while (dataReader.Read()) {
					TF_EventView tF_EventView = MakeTF_EventView(dataReader);
					tF_EventViewList.Add(tF_EventView);
				}
				return tF_EventViewList;
			}
		}
		
		/// <summary>
		/// Creates a new instance of the TF_EventView class and populates it with data from the specified SqlDataReader.
		/// </summary>
		private static TF_EventView MakeTF_EventView(SqlDataReader dataReader) {
			TF_EventView tF_EventView = new TF_EventView();
			
			if (dataReader.IsDBNull(0) == false) {
				tF_EventView.Id = dataReader.GetInt32(0);
			}
			if (dataReader.IsDBNull(1) == false) {
				tF_EventView.CityID = dataReader.GetInt32(1);
			}
			if (dataReader.IsDBNull(2) == false) {
				tF_EventView.ViewId = dataReader.GetInt32(2);
			}
			if (dataReader.IsDBNull(3) == false) {
				tF_EventView.ViewPrice = dataReader.GetDouble(3);
			}
			if (dataReader.IsDBNull(4) == false) {
				tF_EventView.StartDate = dataReader.GetDateTime(4);
			}
			if (dataReader.IsDBNull(5) == false) {
				tF_EventView.EndDate = dataReader.GetDateTime(5);
			}
			if (dataReader.IsDBNull(6) == false) {
				tF_EventView.Memo = dataReader.GetString(6);
			}

			return tF_EventView;
		}
		#endregion
	}
}
